const express = require('express')
// 执行npm install body-parser之后再引入
const bodyParser = require('body-parser');


const getRouter = require('./routes/router/get')
const postRouter = require('./routes/router/post')
const getComment = require('./routes/comment/get')
const postComment = require('./routes/comment/post')
const getCourse = require('./routes/course/get')
const postCourse = require('./routes/course/post')
const io = require('./routes/socket/app')

const app = express()
// 处理application/json内容格式的请求体
app.use(bodyParser.json());
// 处理application/x-www-form-urlencoded内容格式的请求体
app.use(bodyParser.urlencoded({ extended: false }));

app.all("*", (req, res, next) => {
    res.header("Access-Control-Allow-Origin", "*");
    res.header("Access-Control-Allow-Methods", "GET,POST");
    next();
});

app.use(getRouter)
app.use(postRouter)
app.use(getComment)
app.use(postComment)
app.use(getCourse)
app.use(postCourse)
// app.use(io)


app.listen(9000, () => {
    console.log('9000端口监听中，服务已经启动...');
})